<?php
/**
 * Date: 2023/12/22
 * Time: 17:55
 */

namespace App\Console\Commands\AdsApi;


use App\Logic\Amazon\AdsApi\ReportRequest;
use Illuminate\Console\Command;
use JetBrains\PhpStorm\NoReturn;

class CreateAdsReport extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'ads:create-report {date=null} {accountId=0}';

    /**
     * The console command description.
     * @var string
     */
    protected $description = 'exe func';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     */
    #[NoReturn] public function handle(): void
    {
        $accountId = $this->argument('accountId');
        $date = $this->argument('date');

        if ($date == 'null') {
            $startDate = date('Y-m-d',strtotime('-2 days'));
        }else{
            $startDate = $date; //赋值
        }
        $endDate = date('Y-m-d', strtotime($startDate));

        //参数里面的key不可变
        $params = [
            'accountId' => $accountId,
            'SP_AP' => [
                'name' => 'SP APR '.$startDate.'~'.$endDate,
                'startDate' => $startDate,
                "endDate" => $endDate,
            ],
            'SD_AP' => [
                'name' => 'SD APR '.$startDate.'~'.$endDate,
                'startDate' => $startDate,
                "endDate" => $endDate,
            ],
            'SB_C' => [
                'name' => 'SB CR '.$startDate.'~'.$endDate,
                'startDate' => $startDate,
                'endDate' => $endDate,
            ],
            'ST_C' => [
                'name' => 'ST CR '.$startDate.'~'.$endDate,
                'startDate' => $startDate,
                'endDate' => $endDate,
            ],
        ];

        $re = ReportRequest::createReport($params);
        $this->info('finish!');
        dd($re);
    }
}
